package cn.sxw.ld.common.dto;

import lombok.Data;

import java.io.Serial;
import java.io.Serializable;

/**
 * 通用的返回类型，统一返回给前端的数据
 */
@Data
public class R<T> implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    private Integer code;
    private String msg;
    private T data;

    public static <T> R<T> success(T object) {
        R<T> r = new R<>();
        r.setCode(1);
        r.setData(object);
        return r;
    }

    public static <T> R<T> error(String msg) {
        R<T> r = new R<>();
        r.setCode(0);
        r.setMsg(msg);
        return r;
    }
}
